import Foundation
import SwiftData

// To let SwiftData save instances of a model class, import the framework and annotate that class with the Model() macro
// The macro updates the class with conformance to the **PersistentModel protocol**
// enables change tracking for the class by adding conformance to the **Observable protocol**
//
@Model
// 使用final表示这个类不允许被继承
final class Item {
    // The framework supports primitive types such as Bool, Int, and String
    // as well as complex value types such as structures, enumerations
    // and other value types that conform to the **Codable protocol**.
    var timestamp: Date
    
    // To customize an attribute’s behavior, annotate the property with the @Attribute
    // @Attribute(.unique) var name: String
    // Aside from enforcing unique constraints, @Attribute supports, among others, preserving deleted values, Spotlight indexing, and encryption.
    // You can also use the @Attribute macro to correctly handle renamed attributes if you want to preserve the original name in the underlying model data.
    
    // When a model contains an attribute whose type is also a model (or a collection of models), the framework sets relationship attributes to nil after you delete a related model instance.
    // To specify a different deletion rule, annotate the property with the @Relationship
    // For example, you may want to delete any related accommodations when deleting a trip.
    // @Relationship(deleteRule: .cascade) var accommodation: String?
    
    // one or more properties on a class may only ever contain temporary data that doesn’t need saving
    // annotate those properties with the @Transient
    // @Transient var destinationWeather = Weather.current()
    
    init(timestamp: Date) {
        self.timestamp = timestamp
    }
}
